package zhang.test.netfits_youmeng;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class payItemActivity extends AppCompatActivity {

    private static final String TAG = "zhang";
    @BindView(R.id.lv)
    ListView lv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//这句话必须要写
        initUI();
    }

    private void initUI() {
        final List ls = new ArrayList();
        ls.add("item1");
        ls.add("item2");
        ls.add("item3");
        ls.add("item4");
        lv.setAdapter(new ArrayAdapter<String>(this, R.layout.item, R.id.tv, ls));

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(payItemActivity.this, "" + ls.get(i), Toast.LENGTH_SHORT).show();

                HashMap<String, String> map = new HashMap<String, String>();
                map.put("item", ls.get(i) + "");
                MobclickAgent.onEvent(payItemActivity.this, "payItem", map);
                startActivity(new Intent(payItemActivity.this, payModeActivity.class));
            }
        });
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.bind(this).unbind();
    }

    @OnClick({R.id.tv_event_b})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_event_b:
                Toast.makeText(this, "event_b", Toast.LENGTH_SHORT).show();
                List eventlist1 = new ArrayList();
                eventlist1.add("b");
                eventlist1.add("c");
                eventlist1.add("d");
                eventlist1.add("payItem");
                eventlist1.add("e");
                MobclickAgent.onEvent(this, eventlist1, eventlist1.size(), "a");
                break;
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            MobclickAgent.onEvent(payItemActivity.this, "back");
            Log.d(TAG, "onOptionsItemSelected: ");
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
